﻿Public Class frmStudentBillManagement
    Dim frmCtrl As New control
    Dim dbBase As New dbStudent
    Dim dbSys As New dbSystem
    Dim dsBase As DataSet
    Dim curr As New Currency
    Dim TypeAct As String
    Public EntryID As String

    Private Sub LoadData()
        dsBase = dbBase.GetStudentBillDetail(EntryID)
        Dim dtStudentDetail As DataTable = dsBase.Tables(0)
        Dim dtStudentBill As DataTable = dsBase.Tables(1)
        txtStudentID.Text = dtStudentDetail.Rows(0)("stdGenID").ToString()
        txtFullName.Text = dtStudentDetail.Rows(0)("stdFullName").ToString()
        UcGridFilter1.Initialize(dtStudentBill, "sblGenID", UcHeader1, Me, True)
        If (dtStudentBill.Rows.Count > 0) Then
            UcGridFilter1.getDataGridView().Columns("sblGenID").Visible = False
            UcGridFilter1.getDataGridView().Columns("Created Date").DefaultCellStyle.Format = "dd MMM yyyy"
            UcGridFilter1.getDataGridView().Columns("Due Date").DefaultCellStyle.Format = "dd MMM yyyy"
            UcGridFilter1.getDataGridView().Columns("Pay Date").DefaultCellStyle.Format = "dd MMM yyyy"
            UcGridFilter1.getDataGridView().Columns("Amount").DefaultCellStyle.Format = "N2"
            UcGridFilter1.getDataGridView().Columns("Amount").DefaultCellStyle.FormatProvider = System.Globalization.CultureInfo.CreateSpecificCulture("en-US")
        End If
        Dim frm As New frmStudentList
        frm.ModuleName = "Finance"
        UcHeader1.Iniliaze("Management : Student Bill", Me, frm, UcGridFilter1.getDataGridView(), "sblGenID", True)
        Textbox(False, False)
    End Sub

    Private Sub frmStudentBillManagement_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        frmCtrl.reDesign(Me)
        If (EntryID <> "") Then
            LoadData()
        Else
            Dim frm As New frmStudentList
            frm.ModuleName = "Finance"
            UcHeader1.Iniliaze("Management : Student Bill", Me, frm, Nothing, "", True)
            TypeAct = "I"
            Textbox(True, True)
            UcHeader1.ActionCtrl(False, False, False, False, False, True, False, False, False, True)
        End If
    End Sub

    Private Sub Textbox(st As Boolean, clear As Boolean)
        dtpBillDueDate.Enabled = st
        If (st) Then
            st = False
        Else : st = True
        End If
        txtBillNote.ReadOnly = st
        txtBillNote.BackColor = Color.White
        txtBillDesc.ReadOnly = st
        txtBillDesc.BackColor = Color.White
        txtBillAmount.txtcurr.ReadOnly = st
        txtBillAmount.txtcurr.BackColor = Color.White
        UcGridFilter1.Enabled = st
        If (clear) Then
            txtGenID.Text = ""
            txtBillNote.Text = ""
            txtBillDesc.Text = ""
            txtBillWord.Text = ""
            txtBillAmount.txtcurr.Text = "0"
        End If
    End Sub

    Private Sub tsNew_Click(ByVal sender As Object) Handles UcHeader1.tsNewClick
        TypeAct = "I"
        Textbox(True, True)
    End Sub

    Private Sub tsEdit_Click(ByVal sender As Object) Handles UcHeader1.tsEditClick
        TypeAct = "U"
        Textbox(True, False)
    End Sub

    Private Sub tsDelete_Click(ByVal sender As Object) Handles UcHeader1.tsDeleteClick
        If (txtGenID.Text.Trim() <> "") Then
            TypeAct = "D"
            Dim result As Boolean '= dbBase.EmployerManagement(TypeAct, txtGenID.Text.Trim(), txtName.Text.Trim(), txtAddress.Text.Trim(), txtPhone.Text.Trim(), cmbPosition.SelectedValue, frmGlobal.LoginID)
            If (result) Then
                frmCtrl.openChild(New frmStudentBillManagement, Me.ParentForm)
            Else : MessageBox.Show("Error in Delete Progress")
            End If
        Else : MessageBox.Show("Please Choose User First")
        End If
    End Sub

    Private Sub tsPrint_Click(ByVal sender As ucHeader) Handles UcHeader1.tsPrintClick
        ''Event 
        MessageBox.Show("Not included in prototype")
    End Sub

    Private Sub tsSave_Click(ByVal sender As Object) Handles UcHeader1.tsSaveClick
        Dim status As Boolean = True
        If (txtBillNote.Text.Trim() <> "" And txtBillDesc.Text.Trim() <> "" And txtBillAmount.Text.Trim() <> "" And status = True) Then
            Dim result As String = "Not included in prototype" '= dbBase.EmployerManagement(TypeAct, txtGenID.Text.Trim(), txtName.Text.Trim(), txtAddress.Text.Trim(), txtPhone.Text.Trim(), cmbPosition.SelectedValue, frmGlobal.LoginID)
            If (result = "Success") Then
                frmCtrl.openChild(New frmStudentBillManagement, Me.ParentForm)
            Else : MessageBox.Show(result)
            End If
        Else : MessageBox.Show("Please Fill All Field")
        End If
    End Sub

    Private Sub tsRefresh_Click(ByVal sender As Object) Handles UcHeader1.tsRefreshClick
        Dim OpenForm As New frmStudentBillManagement
        OpenForm.EntryID = EntryID
        frmCtrl.OpenFormDetail(Me, OpenForm)
    End Sub

    Private Sub tsCancel_Click(ByVal sender As Object) Handles UcHeader1.tsCancelClick
        Dim OpenForm As New frmStudentBillManagement
        OpenForm.EntryID = EntryID
        frmCtrl.OpenFormDetail(Me, OpenForm)
    End Sub

    Private Sub GridCellEnter_Click(ByVal sender As ucGridFilter, KeyValue As String) Handles UcGridFilter1.GridCellEnter
        Dim dvFind As DataView = New DataView(dsBase.Tables(1))
        dvFind.RowFilter = "[sblGenID] = '" & KeyValue & "'"
        txtGenID.Text = dvFind.Item(0).Row("sblGenID").ToString()
        txtBillNote.Text = dvFind.Item(0).Row("Bill Note").ToString()
        txtBillDesc.Text = dvFind.Item(0).Row("Bill Description").ToString()
        txtBillAmount.txtcurr.Text = curr.dec2curr(CDec(dvFind.Item(0).Row("Amount")))
        dtpBillDueDate.Value = CDate(dvFind.Item(0).Row("Due Date"))
        txtBillWord.Text = curr.NumberToString(dvFind.Item(0).Row("Amount").ToString())
        If (DateTime.Now > dtpBillDueDate.Value) Then
            lblStatusBill.Text = "Due Bill"
            lblStatusBill.BackColor = Color.LightPink
        Else
            lblStatusBill.Text = "Bills Unpaid"
            lblStatusBill.BackColor = Color.LightBlue
        End If
        If (dvFind.Item(0).Row("Pay Date").ToString() <> "") Then
            lblStatusBill.Text = "Bills Paid"
            lblStatusBill.BackColor = Color.LightGreen
        End If
    End Sub
End Class